package wfmanage.action;
import java.util.Map;
import java.lang.Object;
import javax.mail.Message.RecipientType;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.util.MyLog;



public class email {
	
void sendmail(String username,String to,String role,int requestId, String comments){
     
    
    /* Send e-mail*/
	MyLog.log("Getting mail list is"+to);
	System.out.println("Getting mail list is"+to);
    javax.mail.Session defaultSession;
    String  from , host;

    String password;  
        //   to ="sravaniperaka@gmail.com";
         from = "wfmanage";
         password ="satyadeepthi";
         host = "smtp.gmail.com";
         
         try
         {
         java.util.Properties props = System.getProperties(); 
         props.put("mail.smtp.starttls.enable", "true"); 
         props.put("mail.smtp.host", host); 
         props.setProperty("mail.transport.protocol", "smtp");
         props.put("mail.smtp.user", from); 
         props.put("mail.smtp.password", password); 
         props.put("mail.smtp.port", "25"); 
         props.put("mail.smtp.auth", "true"); 
         defaultSession = javax.mail.Session.getDefaultInstance(props, new javax.mail.Authenticator() {
                protected javax.mail.PasswordAuthentication 
                getPasswordAuthentication() {
                return new javax.mail.PasswordAuthentication("wfmanage@gmail.com", "satyadeepthi");
                }}); 
         MimeMessage message = new MimeMessage(defaultSession); 
         InternetAddress fromAddress = null;
         InternetAddress toAddress = null;

         try {
         fromAddress = new InternetAddress(from);
         toAddress = new InternetAddress(to);
         } catch (AddressException e) {

         e.printStackTrace();
         }

         message.setFrom(fromAddress);
         message.addRecipients(RecipientType.TO, to);
         if(role=="vefication_dpt"){
         message.setSubject("New Request came to your Workflow for Verification Approval");
         String emailBody = "Dear "+ username + ", there is a new request in your work flow pending for verification. Please check your Workflow Portal";
         message.setText(emailBody ); 
         }
         else if(role=="finance_dpt"){
             message.setSubject("New Request "+ requestId +" came to your Workflow for Finance Approval");
             String emailBody = "Dear "+ username + ", there is a new request with Req.number "+ requestId +" in your work flow pending for Finance approval. Please check your Workflow Portal";
             message.setText(emailBody ); 
             }
         else if(role=="user"){
             message.setSubject("Your Request No: "+ requestId + "is completed");
             String emailBody = "Dear "+ username + ", Your request " + requestId + " has been completed. Please check your WorkFlow portal";
             message.setText(emailBody); 
             }
         else if(role=="HelpDesk_Admin"){
             message.setSubject("A new ticket has been raised.");
             String emailBody = "Dear "+ username + ", a new ticket has been raised and is waiting to be assigned. Please check your HelpDesk portal.";
             message.setText(emailBody); 
             }
         else if(role=="HelpDesk_User"){
             message.setSubject("Your ticket has been resolved!");
             String emailBody = "Dear "+ username + ", the issue you had raised has been resolved and the ticket is now closed. " 
            		 			+ "The proposed solution to your problem: " + comments;
             message.setText(emailBody); 
             }
         else if(role.startsWith("Support_Executive")){
             message.setSubject("You have been assigned a new ticket!");
             String emailBody = "Dear "+ username + ", you have been assigned a new ticket and is waiting to be resolved. Please check your HelpDesk portal.";
             message.setText(emailBody); 
             }
         else if(role==""||role==null){
             message.setSubject("Your Registrtion to WorkFlow Management Portal is Successful");
             String emailBody = "Dear "+ username + ", Congratulations. Your Registration to WorkFlow Management Portal has been completed Successfully. Please use your username and password to login to WorkFlow portal";
             message.setText(emailBody); 
             }
         else {
             message.setSubject("Tagged with role and LTA LIMIT is set Successfully");
             String emailBody = "Dear "+ username + ", You are tagged with role "+role+" and LTA Limit is set. Please login to WorkFlow Management Portal and check the same. Please contact admin(wfmanage@gmail.com) in case of any concerns/issues";
             message.setText(emailBody); 
             }
         //SMTPSSLTransport transport =(SMTPSSLTransport)session.getTransport("smtps");

         Transport.send(message);
         }catch(Exception ex){
             ex.printStackTrace();
         }
      
    }

}